package de.tu_darmstadt.gdi1.xcom.tests.testcases.students;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;

import org.junit.Before;
import org.junit.Test;

import de.tu_darmstadt.gdi1.xcom.tests.adapters.XcomTestAdapterLevel3;

/**
 * 
 * Tests for "easy" light of sight
 * 
 * @author Lukas Schwoebel
 *
 */
public class HeavyLineOfSightTest {
	
	private XcomTestAdapterLevel3 testAdapter;

	private final String lineOfSightLevel = "" +
			"##############\n" +
			"##..........##\n" +
			"##...##.....##\n" +
			"##..........##\n" +
			"###........###\n" +
			"#....##.....##\n" +
			"#...........##\n" +
			"##############\n" +
			"//{mobs}\n" +
			"//@;5;3;s;50;75;50;50;10\n";
	
	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
		testAdapter = new XcomTestAdapterLevel3();
	}

	/**
	 * Test method for {@link de.tu_darmstadt.gdi1.xcom.tests.adapters.XcomTestAdapterLevel3#isFieldVisible()}.
	 */
	@Test
	public final void testIsFieldVisible() {
		
		testAdapter.loadLevelFromString(lineOfSightLevel);
		
		// this is the extended test with a "light-cone"
		// as the borders might differ, only assured fields are tested
		
		// player is looking south, so only fields south of the player are tested here
		assertTrue("Field 5:4 should be visible", testAdapter.isFieldVisible(5, 4));
		assertTrue("Field 5:5 should be visible", testAdapter.isFieldVisible(5, 5));
		assertTrue("Field 6:5 should be visible", testAdapter.isFieldVisible(6, 5));

		// north fields are invisible
		assertFalse("Field 5:2 should be hidden", testAdapter.isFieldVisible(5, 2));
		assertFalse("Field 5:1 should be hidden", testAdapter.isFieldVisible(5, 1));
		assertFalse("Field 6:2 should be hidden", testAdapter.isFieldVisible(6, 2));
		// same height, still hidden, but don't test the direct neighbors
		assertFalse("Field 7:3 should be hidden", testAdapter.isFieldVisible(7, 3));
		assertFalse("Field 3:3 should be hidden", testAdapter.isFieldVisible(3, 3));
		
		// fields out of the rectangle (and the extended line of sight) should be hidden
		assertFalse("Field 2:3 should be hidden", testAdapter.isFieldVisible(2, 3));
		assertFalse("Field 5:7 should be hidden", testAdapter.isFieldVisible(5, 7));
		
		// now test walls, everything behind a wall should be hidden
		assertFalse("Field 5:6 should be hidden, behind wall", testAdapter.isFieldVisible(5, 6));
		assertFalse("Field 6:6 should be hidden, behind wall", testAdapter.isFieldVisible(6, 6));
	}
}
